<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div>
          <el-date-picker
              v-model="value1"
              type="datetimerange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="handleDateChange">
          </el-date-picker>
        </div>

        <div style="margin-left: 30px">
          <el-input  v-model="listPram.name" placeholder="输入昵称" clearable class="selWidth"/>
        </div>
        <div style="margin-top: 10px;margin-left: 50px">

            <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>

        </div>

      </div>
      <el-table v-loading="formLoading" :data="listData.list" style="width: 100%" size="small" highlight-current-row>
        <el-table-column prop="id" label="ID" min-width="90"/>
        <el-table-column label="头像" prop="avatar">
          <template slot-scope="scope">
            <el-image :src="imageUrl + scope.row.faceUrl"></el-image>
          </template>
        </el-table-column>
        <el-table-column label="昵称" prop="name">
          <template slot-scope="scope">
            <div> {{ scope.row.name || '-' }}</div>
          </template>
        </el-table-column>
        <el-table-column label="手机号" prop="phone"/>
        <el-table-column label="所在地区" prop="cityName"/>
        <el-table-column label="益联券" prop="voucher"/>
        <el-table-column label="积分" prop="integral"/>
        <el-table-column label="邀请时间" prop="createTime" min-width="100"/>
        <el-table-column label="是否成为会员" prop="vip">
          <template slot-scope="scope">
            <span v-if="scope.row.vip==1">是</span>
            <span v-else>否</span>
          </template>
        </el-table-column>
        <el-table-column label="是否为商家" prop="vip">
          <template slot-scope="scope">
            <span v-if="scope.row.status==2">是</span>
            <span v-else>否</span>
          </template>
        </el-table-column>
        <el-table-column label="是否有效" prop="vip">
          <template slot-scope="scope">
            <span v-if="scope.row.inviteStatus==2">有效</span>
            <span v-else>无效</span>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[10,20,50,80,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listData.count"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>
<script>
import {getInviteList} from "@/api/user";

export default {
  components: {},
  props: {
    id: {
      default: null
    }
  },
  data() {
    return {
      imageUrl: '',
      type: 2,
      value1: '',
      recordName: 'couponObtain',
      formLoading: true,
      listData: {list: [], count: 0},
      listPram: {
        page: 1,
        limit: 10,
        dateLimit: '',
        id: '',
        beginTime:'',
        endTime:''
      },
    }
  },
  mounted() {
    this.imageUrl = process.env.VUE_APP_IMAGE_URL
    if (this.id) {
      this.getList();
    }
  },
  methods: {
    handleDateChange(value) {
      this.listPram.beginTime = value[0];
      this.listPram.endTime = value[1];
    },
    handleClick() {
      this.listPram.dateLimit = '';
      this.value1 = '';
      this.getDetail()
    },
    getList() {
      this.listPram.id = this.id
      getInviteList(this.listPram).then(res => {
        this.listData = res
      }).finally(() => {
        this.formLoading = false;
      })
    },
    handlerSubmit() {
      if (this.saveLoading || this.formLoading) {
        return;
      }
    },
    close() {
      this.$emit('hideEditDialog')
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    resetQuery()
    {
      this.listPram.page=1
      this.listPram.name=''
      this.listPram.beginTime = ''
      this.listPram.endTime = ''
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep {
  .el-upload {
  }
}
.clearfix{
  display: flex;
  justify-content: start;
}
.img {
  width: 80px;
  height: 80px;
  border-radius: 100px;
}
</style>
